Router.configure({
  layoutTemplate: 'layout',
  notFoundTemplate: 'not_found'
});

Router.onBeforeAction(function () {
  if (!Meteor.userId()) {
    this.redirect('welcome');
  } else {
    this.next();
  }
}, {
  except: ['welcome', 'homepage']
});

// 首页
Router.route('/', {
  name: 'welcome',
  template: 'welcome',
  yieldRegions: {
    'header': {to: 'header'},
    'footer': {to: 'footer'}
  },
  action: function () {
    DocHead.setTitle('Class / 卡司群聊');
    this.render();
  }
});

// 发现频道
Router.route('/explore/:name', {
  name: 'explore',
  template: 'explore',
  yieldRegions: {
    'header': {to: 'header'},
    'footer': {to: 'footer'}
  },
  action: function () {
    DocHead.setTitle('Class / 发现频道');
    this.render();
  }
});

// 创建新频道
Router.route('/create', {
  name: 'create',
  template: 'create',
  yieldRegions: {
    'header': {to: 'header'},
    'footer': {to: 'footer'}
  },
  action: function () {
    DocHead.setTitle('Class / 创建新频道');
    this.render();
  }
});
// console.log(Router.current())

// 用户个人主页
Router.route('/u/:username', {
  name: 'homepage',
  template: 'homepage',
  yieldRegions: {
    'header': {to: 'header'},
    'footer': {to: 'footer'}
  },
  action: function () {
    DocHead.setTitle('Class / 用户名称');
    this.render();
  }
});

// 群聊界面
Router.route('/channel/:channelId', {
  name: 'channel',
  template: 'channel',
  yieldRegions: {
    'header': {to: 'header'}
  }
});